package com.example.bestapp.bean;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class UserBean {
    @SerializedName("url")
    private String img;
    @SerializedName("desc")
    private String name;
    private boolean isSelect=false;
    public static boolean isShow=false;
    public boolean getSelect(){
        return isSelect;
    }
    public void setSelect(boolean select){
        isSelect=select;
    }
    public UserBean(String img, String name) {
        this.img = img;
        this.name = name;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public static ArrayList<UserBean> loadData(Context context) {
        // 读取
        String json = load(context);
        // 解析
        Gson gson = new Gson();
        TypeToken<ArrayList<UserBean>> typeToken = new TypeToken<>() {};
        ArrayList<UserBean> UserBeans = gson.fromJson(json, typeToken.getType());

        return UserBeans;
    }
    private static String load(Context context) {
        StringBuilder sb=new StringBuilder();
        try {
            InputStream inputStream=context.getAssets().open("defaultdatas.json");
            InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
            BufferedReader bs=new BufferedReader(inputStreamReader);
            String line;
            while ((line=bs.readLine())!=null){
                sb.append(line);
            }
            bs.close();
            inputStream.close();

        }catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}
